﻿using FluentValidation;
using FluentValidation.Attributes;
using Home.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Utilities.Validation.ExtensionMethods;

namespace Home.WebUI.Areas.Admin.Validation
{
    public abstract class VUserInfo
    {
        public int Id { get; set; }       
        /// <summary>
        /// 姓名
        /// </summary>
        public string Name { set; get; }
        /// <summary>
        /// 邮箱
        /// </summary>
        public string Email { set; get; }
        /// <summary>
        /// 公司名称
        /// </summary>
        public string CompanyName { set; get; }
        /// <summary>
        /// 职位
        /// </summary>
        public string Position { set; get; }
        /// <summary>
        /// 电话
        /// </summary>
        public string Phone { set; get; }
        /// <summary>
        /// 业务
        /// </summary>
        public string YeWu { set; get; }
        /// <summary>
        /// 会籍
        /// </summary>
        public string HuiJi { set; get; }
        /// <summary>
        /// 地址
        /// </summary>
        public string Address { set; get; }
        /// <summary>
        /// 状态（1正常，0禁用）
        /// </summary>
        public int State { set; get; }
        public string PassWord { get; set; }
        public string VPassWord { get; set; }
    }
    public abstract class VUserInfoValidator<TUserInfo> : AbstractValidator<TUserInfo> where TUserInfo : VUserInfo
    {
        public VUserInfoValidator()
        {            
            RuleFor(u => u.Name).Length(int.MinValue, 16).WithLocalizedName(() => "姓名");
            RuleFor(u => u.Email).EmailAddress();
            RuleFor(u => u.CompanyName).Length(int.MinValue, 16).WithLocalizedName(() => "公司名称");
            RuleFor(u => u.Position).Length(int.MinValue, 16).WithLocalizedName(() => "职位");
            RuleFor(u => u.Phone).Length(int.MinValue, 16).WithLocalizedName(() => "电话");
            RuleFor(u => u.YeWu).Length(int.MinValue, 16).WithLocalizedName(() => "业务");
            RuleFor(u => u.HuiJi).Length(int.MinValue, 16).WithLocalizedName(() => "会籍");
            RuleFor(u => u.Address).Length(int.MinValue, 16).WithLocalizedName(() => "地址");
            RuleFor(u => u.State).NotNull().WithLocalizedName(() => "状态");
            RuleFor(u => u.VPassWord).Equal(u => u.PassWord).WithMessage("和密码不同");
            RuleFor(u => u.PassWord).Length(6, 16).WithLocalizedName(() => "密码");
        }
    }
    [Validator(typeof(UserInfoCreateValidator))]
    public class UserInfoCreate : VUserInfo
    {
        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName { set; get; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateDate { get { return DateTime.Now; } }
        

    }
    public class UserInfoCreateValidator : VUserInfoValidator<UserInfoCreate>
    {
        public UserInfoCreateValidator()
        {
            RuleFor(u => u.UserName)
              .NotEmpty().WithLocalizedName(() => "用户名").UserName();
            RuleFor(u => u.PassWord).NotEmpty();
        }
    }
     [Validator(typeof(UserInfoEditValidator))]
    public class UserInfoEdit : VUserInfo
    { 
        
    }
    public class UserInfoEditValidator : VUserInfoValidator<UserInfoEdit>
    {
        public UserInfoEditValidator()
        {

        }
    }
}